<template>
  <div class="mine">
    <div class="top">
      <img :src="userInfo.photo" alt="" />
      <div>
        <div class="name">{{ userInfo.name }}</div>
        <div class="time">{{ userInfo.birthday }}</div>
      </div>
    </div>
    <div class="middle">
      <div class="item">
        <van-icon name="newspaper-o" />
        <h3>我的作品</h3>
      </div>
      <div class="item">
        <van-icon name="star-o" />
        <h3>我的收藏</h3>
      </div>
      <div class="item">
        <van-icon name="tosend" />
        <h3>阅读历史</h3>
      </div>
    </div>
    <div class="bottom">
      <!-- 单元格组件
           van-cell
              icon:左边小图标
              title:左边文本内容
              value:右边文本内容
              is-link:右边小箭头          -->
      <van-cell-group>
        <!-- 1:创建编辑页面
          2：配制路由
          3：点击跳转
          4：完成布局 -->

        <van-cell
          icon="edit"
          title="编辑资料"
          is-link
          @click="goEdit"
        ></van-cell>
        <van-cell
          icon="chat-o"
          title="小智同学"
          is-link
          to="/layout/chat"
        ></van-cell>
        <van-cell icon="setting-o" title="系统设置" is-link></van-cell>
        <van-cell
          icon="info-o"
          title="退出登录"
          is-link
          @click="exit"
        ></van-cell>
      </van-cell-group>
    </div>
  </div>
</template>
<script>
// 渲染我的数据  1：定义api  2:导入   3：进入页面调用 4：存储并渲染
// import { userProfile } from '@/api/user'
import { mapState } from 'vuex'
export default {
  data () {
    return {
      // userInfo: ''
    }
  },
  created () {
    console.log('mine created')
    // this.getData()
    this.$store.dispatch('getUserInfo')
  },
  activated () {
    console.log('mine activated')
  },
  computed: {
    ...mapState(['userInfo'])
  },
  methods: {
    // async getData () {
    //   if (!this.userInfo) {
    //     const res = await userProfile()
    //     this.$store.commit('setUserInfo', res.data.data)
    //     // this.userInfo = res.data.data
    //     console.log('userinfo', res)
    //   }
    // },
    // 跳转到编辑页
    goEdit () {
      // this.$router:路由的管理者 跳转路由    this.$route:小秘，获取一些路由基本信息
      this.$router.push('/layout/edit')
    },
    // 退出点击
    exit () {
      this.$dialog
        .confirm({
          title: '提示',
          message: '您确定退出该网站吗?'
        })
        .then(() => {
          this.$store.commit('logout')
        })
        .catch(() => {})
    }
  }
}
</script>
<style lang="less" scoped>
.top {
  background-color: #3296fa;
  height: 150px;
  display: flex;
  align-items: center;
  img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #fff;
    object-fit: cover;
    margin-left: 30px;
    margin-right: 15px;
  }
  .name {
    font-size: 20px;
    font-weight: 500;
    color: #fff;
  }
  .time {
    background-color: #fff;
    color: #3296fa;
  }
}
.middle {
  display: flex;
  justify-content: space-between;
  .item {
    flex: 1;
    text-align: center;
    .van-icon {
      font-size: 30px;
      padding: 10px 0;
    }
    h3 {
      font-weight: 400;
    }
    &:nth-child(1) {
      .van-icon {
        color: #8daaff;
      }
    }
    &:nth-child(2) {
      .van-icon {
        color: #ff3800;
      }
    }
    &:nth-child(3) {
      .van-icon {
        color: #ffb45a;
      }
    }
  }
}
.bottom {
  margin-top: 15px;
}
</style>
